import base64
import hashlib
import time
import uuid
from urllib.parse import urlencode

import requests

timestamp = str(int(time.time() * 1000))

headers = {
    'Accept': 'application/json, text/plain, */*',
    'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
    'Cache-Control': 'no-cache',
    'Connection': 'keep-alive',
    'Pragma': 'no-cache',
    'Referer': 'https://piaofang.maoyan.com/dashboard',
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'same-origin',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0',
    'sec-ch-ua': '"Chromium";v="128", "Not;A=Brand";v="24", "Microsoft Edge";v="128"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
}

params = {
    'orderType': '0',
    'uuid': '1918ebfa57dc8-066c976d2ff785-4c657b58-1fa400-1918ebfa57dc5',
    'timeStamp': timestamp,
    'User-Agent': base64.b64encode(headers['User-Agent'].encode('utf-8')).decode('utf-8'),
    'index': '351',
    'channelId': '40009',
    'sVersion': '2',
}
md5 = hashlib.md5(urlencode(params).encode('utf-8')).hexdigest()
params['signKey'] = md5

response = requests.get('https://piaofang.maoyan.com/dashboard-ajax',
                        params=params,
                        headers=headers,
                        verify=False
                        )

print(response.json())

# datas = list()
# for it in response.json()['movieList']['data']['list']:
#     temp = {}
#     temp["电影ID"] = it['movieInfo']['movieId']
#     temp["电影名称"] = it['movieInfo']['movieName']
#     temp["综合票房"] = it['sumBoxDesc']
#     temp["综合票房占比"] = it['boxRate']
#     temp["排片占比"] = it['showCountRate']
#     temp["排坐占比"] = it['seatCountRate']
